#include "key_process.h"
#include "key_scan.h"
#include "uart_send.h"
#include "string.h"

key_para_t key_para;


static void Msg_K1_Handle(void)
{
    key_para.send_value = KEY_K1_VALUE;                                                                                                                                               key_para.send_value = KEY_K1_VALUE;
}


static void Msg_K2_Handle(void)
{
    key_para.send_value = KEY_K2_VALUE;

}

static void Msg_K3_Handle(void)
{
    key_para.send_value = KEY_K3_VALUE;

}

static void Msg_K4_Handle(void)
{
    key_para.send_value = KEY_K4_VALUE;
}

static void Msg_K5_Handle(void)
{
    key_para.send_value = KEY_K5_VALUE;
}

static void Msg_K6_Handle(void)
{
    key_para.send_value = KEY_K6_VALUE;
}

static void Msg_K7_Handle(void)
{
    key_para.send_value = KEY_K7_VALUE;
}

static key_func_t key_func[] = {
    {MSG_K1_PRESS, Msg_K1_Handle},
    {MSG_K2_PRESS, Msg_K2_Handle},
    {MSG_K3_PRESS, Msg_K3_Handle},
    {MSG_K4_PRESS, Msg_K4_Handle},
    {MSG_K5_PRESS, Msg_K5_Handle},
    {MSG_K6_PRESS, Msg_K6_Handle},
    {MSG_K7_PRESS, Msg_K7_Handle},

};

void Key_Process_Init(void)
{
	Key_Init();
	memset(&key_para, 0, sizeof(key_para_t));
}


void Key_Handle(uint16_t cmd)
{
    if (MSG_INVALID == cmd)
        return ;
    if (key_para.cur_value != cmd) {
        key_para.cur_value = cmd;
        switch (key_para.cur_value) {
            case 0 : {
					key_para.send_value = 0;
                break;
            }

            default : {
                unsigned char i;
                for (i = 0; i < sizeof(key_func) / sizeof(key_func[0]); i++) {
                    if (key_para.cur_value == key_func[i].index) {
                        if (key_func[i].func) {
                            key_func[i].func();
                        }
                    }
                }
                break;
            }
        }
    }
}
